package com.qxgltj.qxgl.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import com.qxgltj.qxgl.dao.IModulesDao;
import com.qxgltj.qxgl.dto.ModulesDTO;
import com.qxgltj.qxgl.model.Modules;
import com.qxgltj.qxgl.service.IModulesService;

import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;

@ApiOperation("模块管理")
@RestController
@RequestMapping("/module")
public class ModulesController {
@Resource
public IModulesDao modulesDao;
@Resource
private IModulesService modulesService;
@ApiOperation(value = "查询所有模块信息",notes = "查询所有模块信息")
@GetMapping
public List<Modules> findAll(){
    return modulesDao.findAll();
}
@ApiOperation(value = "查询所有",notes = "查询所有")
@GetMapping(value = "/findAll")
public Map  findAll(ModulesDTO dto){
    List<Modules> list=modulesDao.findAll();
    Map<String,Object> map=new HashMap<String,Object>();
    map.put("code",0);
    map.put("count",100);
    map.put("msg","查询成功");
    map.put("data", list);
    return map;
}
@ApiOperation(value = "创建模块",notes = "添加或修改")
@PostMapping("/addModules")
 public Modules saveModules(@RequestBody Modules m){
     return modulesService.saveModules(m);
 }
 @ApiOperation(value = "删除",notes = "删除")
 @ApiImplicitParam(name = "id",value = "主键",required = true,paramType = "path")
  @DeleteMapping("/{id}")
  public void del(@PathVariable String id){
      modulesService.del(id);
  }
    @ApiOperation(value = "给角色设置权限")
	@PostMapping("/setRoles")
	public void SetModules(String role_id,@RequestParam List<Integer> ModulesIdList){
		modulesService.SetModules(role_id, ModulesIdList);
	
    }
    @ApiOperation(value = "获取当前角色已存在的权限")
    @GetMapping(value = "/findAllModules/{role_id}")
    public List<Modules> findAllModules(@PathVariable int role_id){
           return modulesDao.findAllRoles(role_id);
    }
}